package cn.lg.soar.flow.api.utils;

import cn.lg.soar.core.util.SoarSubscriber;
import cn.lg.soar.flow.api.model.*;
import cn.lg.soar.flow.api.service.IFlowTaskApi;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.Collection;
import java.util.List;

/**
 * @author luguoxiang
 * @date 2025-07-15
 * 开源项目：https://gitee.com/lgx1992/lg-soar 求star！请给我star！请帮我点个star！
 */
public class FlowTaskUtils {

    private static IFlowTaskApi api;
    static {
        SoarSubscriber.subscribeInit(applicationContext -> {
            api = applicationContext.getBean(IFlowTaskApi.class);
        });
    }

    /**
     * 启动流程
     * @param startFlowDTO
     * @return
     */
    public static FlowInfoDTO startFlow(StartFlowDTO startFlowDTO) {
        return api.startFlow(startFlowDTO);
    }

    /**
     * 完成任务
     * @param completeTaskDTO
     * @return
     */
    public static FlowInfoDTO completeTask(CompleteTaskDTO completeTaskDTO) {
        return api.completeTask(completeTaskDTO);
    }

    /**
     * 撤销流程
     * @param revokeDTO
     */
    public static void revoke(RevokeDTO revokeDTO) {
        api.revoke(revokeDTO);
    }

    /**
     * 当前任务
     * @param userId 用户id
     * @param procInstId 流程实例id
     * @return
     */
    public static List<ApprovalTaskDTO> approvalTasks(Long userId, String procInstId) {
        return api.approvalTasks(userId, procInstId);
    }

    /**
     * 获取用户当前流程实例id
     * @param userId
     * @param flowCode
     * @return
     */
    public static List<String> currentProcInstIds(Long userId, String flowCode) {
        return api.currentProcInstIds(userId, flowCode);
    }

    /**
     * 当前任务和审批人
     * @param procInstIds
     * @return
     */
    public static List<TaskInfoDTO> currentTaskUserIds(Collection<String> procInstIds) {
        return api.currentTaskUserIds(procInstIds);
    }

    /**
     * 流程当前任务
     * @param procInstIds
     * @return
     */
    public static List<TaskInfoDTO> currentTasks(Collection<String> procInstIds) {
        return api.currentTasks(procInstIds);
    }

    /**
     * 审批日志
     * @param procInstId 流程实例id
     * @return
     */
    public static List<AuditLogDTO> auditLogList(String procInstId) {
        return api.auditLogList(procInstId);
    }

    /**
     * 审批记录
     * @param flowCode 流程code
     * @param bizId 业务id
     * @return
     */
    public static List<AuditLogDTO> auditLogList(String flowCode, String bizId) {
        return api.auditLogList(flowCode, bizId);
    }

    /**
     * 流程进度
     * @param procInstId
     * @return
     */
    public static ProgressVO progress(@RequestParam("procInstId") String procInstId) {
        return api.progress(procInstId);
    }

    /**
     * 任务详情
     * @param taskId
     * @return
     */
    public static TaskDetailDTO taskDetail(String taskId) {
        return api.taskDetail(taskId);
    }

}
